
import { getPage, getImage } from '../../utils/config';
import api from '../../utils/api';
import wxApi from '../../utils/wxApi';
import { promisify, http, storage, $toast, $loading, $query, $jumpPages } from '../../utils/utils';
import initSKU from 'sku';
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: 0,
        getPage: getPage,
        getImage: getImage,
        active: 0,
        getPages: 0,
        navbar: {},
        window: {},
        opacity: 0,
        logged: 0,
        userId: '',
        userRank: '',
        scrollActive: 'swiper_anchor',
        goodsInfo: [],
        goodsId: 3173,
        favorite: 0,
        goodsActionHeight: 0,
        couponInfo: [],
        commentsInfo: [],
        goodsCellSpec: [],
        productSpec: [],
        shopScore: 50,
        currentIndex: 1,
        currentIdx: 0,
        playStatus: false,
        specPopupInfo: {},
        chooseCount: 0, //属性已选择种类
        buyCount: 1,
        buyMinCount: 1, //默认购买最小数
        buyGoodsId: 0,
        sheetActionBtn: 0,//0-加入购物车与立即购买 1-加入购物车确定 2-立即购买确定
        timesHours: 0,
        timesMinute: 0,
        timesSecond: 0,
        timesEnd: 1,
        showCoupon: false,
        showParams: false,
        showSpec: false,
    },

    SKUResult: {},

    toggle(type) {
        this.setData({
            [type]: !this.data[type]
        });
    },

    doNothing(){},

    /**
     * 返回上一页
     */
    goBackTap() {
        //存在上一页,关闭当前返回一层,//没有上一页，跳回首页
        this.data.getPages > 1 ? wxApi.navigateBack(1) : wxApi.switchTab(getPage.home);
    },

    /**
     * 跳转店铺
     */
    jumpShop() {
        wxApi.navigateTo(getPage.shop, { 
            id: this.data.goodsInfo.data.shopno
        })
    },

    /**
     * 跳转购物车
     */
    goCartClick() {
        wxApi.refreshPage(getPage.cart);
    },
    
    /**
     * 数组跳过空,计算长度
     */
    arrLenght(arr) {
        let n = 0;
        for (let i in arr) {
            n++
        }
        return n;
    },

    /**
     * 跳转登录页
     */
    goLogin() {
        wxApi.setStartPage({
            id: this.data.goodsInfo.info.id
        });
        wxApi.navigateTo(getPage.login);
    },

    /**
     * 优惠券显示/隐藏
     */
    toggleCoupon() {
        this.toggle('showCoupon');
    },

    /**
     * 参数显示/隐藏
     */
    toggleParams() {
        this.toggle('showParams');
    },

    /**
     * 规格显示/隐藏
     */
    toggleSpec(e) {
        const data = e.currentTarget.dataset || e.target.dataset;
        if(data.tap){
            this.setData({
                sheetActionBtn: data.tap
            })
        }
        this.toggle('showSpec');
    },

    /**
     * 视频控制
     */
    swiperControlsClick(e) {
        const { id } = e.currentTarget.dataset || e.target.dataset;
        const { currentIdx } = this.data;

        if (id != currentIdx){
            this.setData({ currentIdx: id })
        }
    },

    /**
     * 视频播放
     */
    playClick() {
        const { playStatus } = this.data;

        if (!playStatus){
            this.videoContext.play();
            this.toggle('playStatus');
        }
    },

    /**
     * 播放完毕
     */
    playended() {
        this.toggle('playStatus');
    },

    /**
     * 视频错误
     */
    playerror() {
        $toast(`播放视频发生错误`);
    },

    /**
     * 图片轮播
     */
    swiperChange(e) {
        const { current } = e.detail;
        const { playStatus } = this.data;

        this.setData({
            currentIndex: current + 1,
            currentIdx: current,
        });
        if (playStatus) {
            console.log(this.videoContext);
            this.videoContext.pause();
            this.toggle('playStatus');
        }
    },

    /**
     * 预览图片
     */
    prevViewTap(e) {
        const data = e.currentTarget.dataset || e.target.dataset;
        const id = data.id;
        const src = data.src;
        let urls = [];

        this.data.goodsInfo.data.piclist.forEach((item) => {
            urls.push(api.imageCdn + item.img_url);
        })

        wx.previewImage({
            current: api.imageCdn + src, 
            urls: urls
        });
    },

    /**
     * 评论图片
     */
    commentsImageTap(e) {
        const data = e.currentTarget.dataset || e.target.dataset;
        const src = data.src;
        let urls = [];

        this.data.commentsInfo.pic.forEach((item) => {
            urls.push(api.imageCdn + item);
        })

        wx.previewImage({
            current: api.imageCdn + src,
            urls: urls
        })
    },

    /**
     * 规格图片放大
     */
    specThumbTap(e) {
        const data = e.currentTarget.dataset || e.target.dataset;
        const src = data.src;

        wx.previewImage({
            current: src,
            urls: [src]
        })
    },

    //处理cell规格
    cellSpec(arr,callback) {
        if(typeof(arr) === 'null' || typeof(arr) === 'undefined') return arr;
        let spacImage = [];
        for(let i in arr){
            for (let j in arr[i].spec_value_list) {
                let value = arr[i].spec_value_list[j];
                if (value.spec_image && typeof (value.spec_image) !== 'undefined') {
                    let spacList = arr[i].spec_value_list;
                    spacImage.push({
                        spec_value_list:[]
                    });
                    for (let k in spacList){
                        if (spacList[k].spec_image && typeof (spacList[k].spec_image) !== 'undefined') {
                            spacImage[0].spec_value_list.push({
                                image: spacList[k].spec_image
                            })
                        }
                    }
                    spacImage[0].spec_length = arr[i].spec_value_list.length;
                    spacImage[0].spec_show_type = arr[i].spec_show_type;
                    spacImage[0].spec_type = arr[i].spec_type;
                    spacImage[0].spec_name = arr[i].spec_name;
                    spacImage[0].spec_id = arr[i].spec_id;
                    callback && callback(spacImage);
                    return false;
                }
            }
        }
    },

    //处理cell评价
    cellComments(arr) {
        if(arr.length === 0 || typeof(arr) === 'undefined') return arr;
        //判断是否存在图片
        if(arr[0].pic && typeof(arr[0].pic) !== 'undefined'){
            arr[0].pic = arr[0].pic.split(",");
        }
        return arr[0];
    },

    /**
     * 收藏
     */
    addCollectClick() {
        const { logged, favorite } = this.data;
        if (logged){
            if (!favorite) {
                http.post(api.default, {
                    data: {
                        action: 'AddFavorite',
                        userid: this.data.userId,
                        prid: this.data.goodsId,
                    }
                }).then((res) => {
                    this.setData({
                        favorite: 1
                    });

                    $toast('商品收藏成功', {
                        icon: 'success'
                    })
                });
            } else {
                $toast('商品已收藏哦~')
            }
        }else{
            this.goLogin();
        }
    },

    /**
     * SKU选择
     */
    specActive: [],

    specItemClick(e) {
        const event = e.currentTarget.dataset || e.target.dataset;

        //没有禁用
        if(event.disabled){
            const skuResult = this.SKUResult;
            const productSpec = this.data.productSpec;
            const specPopupInfo = this.data.specPopupInfo;
            //没有选择中
            if (event.active == 0){
                //循环点击指定的对象，如果下标相同高亮，否则恢复原来
                productSpec[event.parentId].spec_value_list.forEach((item, index) => {
                    if(event.id === index){
                        item['active'] = 1;
                        this.specActive[event.parentId] = item;
                    }else{
                        item['active'] = 0;
                    }
                });
            }else{
                productSpec[event.parentId].spec_value_list[event.id]['active'] = 0;
                this.specActive.forEach((item, index) => {
                    if(item.spec_private_value_id == event.aid){
                        this.specActive.splice(index, 1);
                    }
                })
            }

            if (this.arrLenght(this.specActive)){
                let selectedIds = [];
                let attrName = [];

                //设置主图
                for (let i = 0; i <= this.specActive.length - 1; i++) {
                    if(this.specActive[i] !== undefined){
                        if (this.specActive[i].spec_image) {
                            specPopupInfo.thumb = this.specActive[i].spec_image;
                            break;
                            //如果最后一个都没有图片改成默认
                        } else if(i === this.arrLenght(this.specActive) - 1){
                            specPopupInfo.thumb = this.data.goodsInfo.data.piclist[0].img_url;
                        }
                    }
                };

                //选择的文本
                this.specActive.forEach((item) => {
                    attrName.push(item.spec_value);
                });

                specPopupInfo.selected = `已选择："${attrName.join('、')}"`;
                
                //选择aid
                this.specActive.forEach((item) => {
                    selectedIds.push(item.spec_private_value_id);
                });

                selectedIds.sort((val1, val2) => {
                    return parseInt(val1) - parseInt(val2);
                });

                let _length = selectedIds.length;
                let skuData = skuResult[selectedIds.join(';')];
                let prices = skuData.prices;
                let maxPrice = Math.max.apply(Math, prices);
                let minPrice = Math.min.apply(Math, prices);
                let activityPrices = skuData.activityprices;
                let maxActivityPrice = Math.max.apply(Math, activityPrices);
                let minActivityPrice = Math.min.apply(Math, activityPrices);

                //产生组合的goodsId
                if(_length === productSpec.length){
                    //价格显示
                    if (this.data.goodsInfo.info.isspecialoffer != 1) {
                        specPopupInfo.price = maxPrice > minPrice ? minPrice + "-" + maxPrice : maxPrice
                    } else {
                        specPopupInfo.price = maxActivityPrice > minActivityPrice ? minActivityPrice + "-" + maxActivityPrice : maxActivityPrice
                    }

                    //库存
                    if (skuData.storage > 0) {
                        specPopupInfo.count = skuData.storage
                        this.setData({
                            buyMinCount: 1,
                        })
                    } else {
                        specPopupInfo.count = 0;
                        //购买数数等于零
                        this.setData({
                            buyMinCount: 0,
                        })
                    }

                    //组合图片
                    if (skuData.pic_url){
                        specPopupInfo.thumb = skuData.pic_url;
                    }

                    //购买商品最后id
                    this.setData({
                        buyGoodsId: skuData.good_id,
                    })
                }else{
                    specPopupInfo.price = '--';
                    specPopupInfo.count = 0;
                }

                //筛选出禁用
                productSpec.forEach((parentItem) => {
                    parentItem.spec_value_list.forEach((item) => {

                        let testAttrIds = [];//从选中节点中去掉选中的兄弟节点
                        let siblingsSelectedObjId;

                        parentItem.spec_value_list.forEach((item1) => {
                            if(item1.active == 1){
                                siblingsSelectedObjId = item1.spec_private_value_id; 
                            }
                        })

                        if(siblingsSelectedObjId){
                            for (let i = 0; i < _length; i++) {
                                (selectedIds[i] != siblingsSelectedObjId) && testAttrIds.push(selectedIds[i]);
                            }
                        } else {
                            testAttrIds = selectedIds;
                        }

                        if(item.spec_id!=event.specId){
                            testAttrIds = testAttrIds.concat(item.spec_private_value_id);
                            testAttrIds.sort((val1, val2) => {
                                return parseInt(val1) - parseInt(val2);
                            });

                            if(!skuResult[testAttrIds.join(';')]) {
                                item.disabled = 0;
                                item.active = 0;
                            } else {
                                item.disabled = 1
                            }
                        }
                    }) 
                })
            }else{
                specPopupInfo.price = '--';
                specPopupInfo.count = '--';
                specPopupInfo.selected = '请选择规格';
                specPopupInfo.thumb = this.data.goodsInfo.data.piclist[0].img_url;
            }
            console.log(this.specActive);
            //改变结果
            this.setData({
                chooseCount: this.arrLenght(this.specActive),
                productSpec: productSpec,
                specPopupInfo: specPopupInfo,
            })
        }
    },

    /**
     * 购买数量
     */
    stepperChange(e) {
        if (e.detail > this.data.specPopupInfo.count){
            $toast(`购买库存最大${this.data.specPopupInfo.count}件`);
        }

        this.setData({
            buyCount: e.detail
        })
    },

    /**
     * 获取商品信息 
     */
    getGoodsInfo() {
        //获取产品信息
        http.get(api.default, {
            data: {
                action: 'GetProduct',
                id: this.data.goodsId,
                userid: this.data.userId,
                user_rank: this.data.userRank,
            }
        },false).then(res => {
            const goodsData = res.data.data;

            let specList = [];
            this.cellSpec(goodsData.data.product_spec_list, (data) => {
                specList = data;
            })
            
            //SKU组合
            if (goodsData.data.PRODUCT_HASH.length) {
                let data = '{';
                for (let i = 0; i < goodsData.data.PRODUCT_HASH.length; i++) {
                    let item = goodsData.data.PRODUCT_HASH[i];
                    let reg = new RegExp('_', 'g');
                    data += `"${item.goodsinfo.spec_private_value_id.replace(reg, ";")}":{
                        "price": ${item.goodsinfo.price},
                        "storage": ${item.goodsinfo.storage},
                        "activityprice": ${item.goodsinfo.activityprice},
                        "marketprice": ${item.goodsinfo.marketprice},
                        "good_id": ${item.good_id},
                        "pic_url": "${item.goodsinfo.pic_url}"
                    },`;
                }
                data = data.substring(0, data.length - 1);
                data += "}";
                this.SKUResult = initSKU(JSON.parse(data));
            }

            //合成最后spec
            let productSpec = [];
            if (goodsData.data.product_spec_list){
                productSpec = goodsData.data.product_spec_list;
            }
            if (productSpec.length){
                productSpec.forEach((key) => {
                    key.spec_value_list.forEach((item) => {
                        item['active'] = 0;
                        this.SKUResult[item.spec_private_value_id] ? item['disabled'] = 1 : item['disabled'] = 0;
                    })
                })
            }

            //倒计时
            let times = (new Date(goodsData.endtime / 1000).getTime() * 1000 - new Date().getTime()) / 1000;
            const timer = setInterval(() => {
                let day = 0,
                    hours = 0,
                    minute = 0,
                    second = 0;
                
                //先减去默认1秒
                times--;

                //如果倒计时大于零
                if (times > 0){
                    hours = Math.floor(times / (60 * 60));
                    minute = Math.floor(times / 60) - (hours * 60);
                    second = Math.floor(times) - (hours * 60 * 60) - (minute * 60);
                    
                    this.setData({
                        timesHours: hours,
                        timesMinute: minute,
                        timesSecond: second,
                    })
                }else{
                    this.setData({
                        timesHours: 0,
                        timesMinute: 0,
                        timesSecond: 0,
                        timesEnd: 0,
                        'goodsInfo.info.isspecialoffer': 0,
                    })
                    clearInterval(timer);
                }
            },1000)

            this.setData({
                goodsInfo: goodsData,
                favorite: goodsData.is_favorite,
                goodsCellSpec: specList,
                commentsInfo: this.cellComments(goodsData.data.pingjia_list),
                shopScore: ( goodsData.data.score / 5) * 50,
                specPopupInfo: {
                    thumb: goodsData.data.piclist[0].img_url,
                    price: goodsData.data.price,
                    count: goodsData.data.product_count,
                    selected: '请选择规格',
                },
                buyMinCount: goodsData.data.product_count === 0 ? 0 : 1,
                productSpec: productSpec,
                videoNo: goodsData.info.video_url ? true : false,
                loading: 1,//显示页面
            });

            //获取优惠券信息
            this.getCouponInfo(() => {}, false);
        })
    },

    /**
     * 获取购物车数量
     */
    getCartInfo() {
        const { logged, userId, userRank } = this.data;
        if(logged){
            http.get(api.default, {
                data: {
                    action: 'getcartlist',
                    userid: userId,
                    user_rank: userRank,
                }
            },false).then((res) => {
                this.setData({
                    cartCount: res.data.data.count
                });
                //更新购物车
                app.setCart(res.data.data.count);
            })
        }
    },

    /**
     * 获取优惠券
     */
    getCouponInfo(callback, bool = true) {
        http.post(api.default, {
            data: {
                action: 'getcouponsfromshop',
                userid: this.data.userId,
                shopid: this.data.goodsInfo.info.shopId,
            }
        },bool).then(res => {
            this.setData({
                couponInfo: res.data.data,
            })
            callback && callback();
        })
    },

    /**
     * 点击领取优惠券
     */
    couponTap(e) {
        const data = e.currentTarget.dataset || e.target.dataset;
        if (this.data.logged) {
            //判断是否是自己店铺的优惠券
            if (this.data.userId !== this.data.goodsInfo.data.shop_userid) {
                http.post(api.default, {
                    data: {
                        action: 'getshopcoupon',
                        userid: this.data.userId,
                        CouponId: data.id,
                    }
                }).then(res => {
                    //重新获取优惠券
                    this.getCouponInfo(() => {
                        $toast(`优惠券领取成功`);
                    },false);
                })
            } else {
                $toast(`不能领取自己店铺的优惠券`)
            }
        } else {
            //跳转登录页
            this.goLogin()
        }
    },

    /**
     * navtabs点击定位
     */
    navtabsChange(e) {
        const index = e.detail.index;
        const arr = ['swiper_anchor', 'comments_anchor', 'detail_anchor','recommend_anchor'];

        this.setData({
            scrollActive: arr[index],
            active: index,
        });
    },

    /**
     * scroll滚动事件
     */
    scrollTop(e) {
        const { scrollTop } = e.detail;
        let { navbar, window, active, playStatus, goodsActionHeight } = this.data;
        const h = navbar.top + navbar.height + 6;
        let opy = (((scrollTop / (h / 1)) > 1) ? 1 : (scrollTop / (h / 1)));
        
        $query.select('#swiper_anchor,#comments_anchor,#detail_anchor,#recommend_anchor', (data) => {
            //向下
            if (active + 1 <= 2 && data[active + 1].top < 0) {
                this.setData({ active: active + 1 })

            } else if (active + 1 === 3 && data[active + 1].top < 0) {
                this.setData({ active: 3 });
            }

            //向上
            if (active - 1 >= 0 && data[active].top - 10 > 0){
                this.setData({ active: active - 1 })
            }
        });

        //视频处理
        if (scrollTop > window.windowWidth && playStatus){
            this.videoContext.stop();
            this.toggle('playStatus');
        }

        this.setData({
            scrollTop: scrollTop,
            opacity: opy,
        });

        if (goodsActionHeight <= 0){
            $query.select('#goodsAction', (res) => {
                if (res) {
                    this.setData({ goodsActionHeight: res.height });
                }
            })
        }
    },

    /**
     * 浮动加入购物车事件
     */
    addCartClick(e) {
        if(this.data.logged){
            if (this.data.goodsInfo.data.product_spec_list && this.data.goodsInfo.data.product_spec_list !== null){
                this.toggleSpec(e);
            } else {
                //加入购物车code
                //判断是否是自己购买自己的产品
                if(this.data.userId !== this.data.goodsInfo.data.shop_userid){
                    http.post(api.default, {
                        data: {
                            action: 'add-cart',
                            userid: this.data.userId,
                            product_id: this.data.goodsId,
                            goods_num: this.data.buyCount,
                            subtype: '',
                            user_rank: this.data.userRank,
                        }
                    }).then(res => {
                        $toast(`加入购物车成功`, {
                            icon: 'success'
                        });
                        //重新获取购物车数量
                        this.getCartInfo();
                        //恢复数据
                        this.resetData();
                    })
                }else{
                    $toast(`不能购买自己店铺的产品`)
                }
            }
        }else{
            //跳转登录页
            this.goLogin()
        }
    },

    /**
     * 浮动立即购买事件
     */
    buyNowClick(e) {
        if (this.data.logged) {
            if(this.data.goodsInfo.data.product_spec_list && this.data.goodsInfo.data.product_spec_list !== null){
                this.toggleSpec(e);
            } else {
                //跳转购买code
                //判断是否是自己购买自己的产品
                if (this.data.userId !== this.data.goodsInfo.data.shop_userid) {
                    http.post(api.default, {
                        data: {
                            action: 'add-cart',
                            userid: this.data.userId,
                            product_id: this.data.goodsId,
                            goods_num: this.data.buyCount,
                            subtype: 'BUY_NOW',
                            user_rank: this.data.userRank,
                        }
                    }).then(res => {
                        wxApi.navigateTo(getPage.order, {
                            cartId: res.data.data.join('_'),
                            source: 1,
                        });
                        //重新获取购物车数量
                        this.getCartInfo();
                        //恢复数据
                        this.resetData();
                    })
                } else {
                    $toast(`不能购买自己店铺的产品`)
                }
            }
        } else {
            //跳转登录页
            this.goLogin()
        }
    },

    /**
     * 规格选择加入购物车
     */
    addCartSpecClick() {
        if (this.data.logged) {
            //判断规格是否选择全部
            if (this.data.chooseCount === this.data.productSpec.length){
                //判断是否是自己购买自己的产品
                if (this.data.userId !== this.data.goodsInfo.data.shop_userid) {
                    http.post(api.default,{
                        data: {
                            action: 'add-cart',
                            userid: this.data.userId,
                            product_id: this.data.goodsId,
                            good_id: this.data.buyGoodsId,
                            goods_num: this.data.buyCount,
                            subtype: '',
                            user_rank: this.data.userRank,
                        }
                    },false).then(res => {
                        $toast(`加入购物车成功`,{
                            icon: 'success'
                        });
                        //重新获取购物车数量
                        this.getCartInfo();
                        //恢复默认数据
                        this.resetData();
                    });
                } else {
                    $toast(`不能购买自己店铺的产品`)
                }
                this.toggle('showSpec');
            }else{
                $toast(`请选择规格`)
            }
        } else {
            //跳转登录页
            this.goLogin()
        }
    },

    /**
     * 规格购买
     */
    buyNowSpecClick() {
        if (this.data.logged) {
            //判断规格是否选择全部
            if (this.data.chooseCount === this.data.productSpec.length) {
                //判断是否是自己购买自己的产品
                if (this.data.userId !== this.data.goodsInfo.data.shop_userid) {
                    http.post(api.default, {
                        data: {
                            action: 'add-cart',
                            userid: this.data.userId,
                            product_id: this.data.goodsId,
                            good_id: this.data.buyGoodsId,
                            goods_num: this.data.buyCount,
                            subtype: 'BUY_NOW',
                            user_rank: this.data.userRank,
                        }
                    }).then((res) => {
                        wxApi.navigateTo(getPage.order, {
                            cartId: res.data.data.join('_'),
                            source: 1,
                        });
                        //重新获取购物车数量
                        this.getCartInfo();
                        //恢复数据
                        this.resetData();
                    });

                } else {
                    $toast(`不能购买自己店铺的产品`)
                }
                this.toggle('showSpec');
            } else {
                $toast(`请选择规格`)
            }
        } else {
            //跳转登录页
            this.goLogin()
        }
    },

    /**
     * 恢复数据
     */
    resetData() {
        this.specActive = [];
        //合成最后spec
        const goodsInfo = this.data.goodsInfo;
        let productSpec = [];
        if (goodsInfo.data.product_spec_list) {
            productSpec = goodsInfo.data.product_spec_list;
        }
        if (productSpec.length) {
            productSpec.forEach((key) => {
                key.spec_value_list.forEach((item) => {
                    item['active'] = 0;
                    this.SKUResult[item.spec_private_value_id] ? item['disabled'] = 1 : item['disabled'] = 0;
                })
            })
        }
        
        this.setData({
            goodsInfo: goodsInfo,
            buyCount: 1,
            buyGoodsId: 0,
            chooseCount: 0,
            specPopupInfo: {
                thumb: goodsInfo.data.piclist[0].img_url,
                price: goodsInfo.data.price,
                count: goodsInfo.data.product_count,
                selected: '请选择规格',
            },
            buyMinCount: goodsInfo.data.product_count === 0 ? 0 : 1,
            productSpec: productSpec,
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        //携带参数
        if(JSON.stringify(options) != '{}'){
            this.setData({ goodsId: options.id });
        }

        //获取system信息
        promisify(wx.getSystemInfo)().then(res => {
            //获取右上角胶囊信息
            this.setData({
                navbar: wx.getMenuButtonBoundingClientRect(),
                window: res,
            })
        });

        //获取路由数量
        this.setData({
            getPages: getCurrentPages().length
        })

        //判断是否登录
        app.getLogin().then((res) => {
            this.setData({
                logged: res.code,
                userId: res.data.user.user_id,
                userRank: res.data.user.user_rank,
            })
            //获取商品信息
            this.getGoodsInfo();
            //获取购物车数量
            this.getCartInfo();
        }).catch((res) => {
            this.setData({ logged: res });
            //获取商品信息
            this.getGoodsInfo();
        });
    },

    /**
     * 页面滚动函数--监听页面滚动事件
     */
    onPageScroll(e) {
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        //获取底部高度
        $query.select('#goodsAction', (res) => {
            if (res) {
                this.setData({
                    goodsActionHeight: res.height
                })
            }
        });

        //视频配置
        this.videoContext = wx.createVideoContext('video');
    }, 

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        const { logged, loading, goodsId } = this.data;
        if (logged == 0 && loading == 1){
            this.onLoad({ id: goodsId });
        }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 右上角分享事件
     */
    onShareAppMessage(res) {
        return {
            title: `【茶店网】${this.data.goodsInfo.info.productname}`,
            imageUrl: api.imageCdn + this.data.goodsInfo.data.piclist[0].img_url,
            path: `${getPage.goods}?id=${this.data.goodsId}`,
        }
    }
})